package com.ziyia.a3_4_all;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.LocaleList;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void test(View view) {
        StringBuilder stringBuilder = new StringBuilder();

        Configuration c = getResources().getConfiguration();


        stringBuilder.append("屏幕方向：" + ((c.orientation == Configuration.ORIENTATION_LANDSCAPE) ? "横向屏幕" : "竖向屏幕"));
        stringBuilder.append('\n');
        stringBuilder.append("触摸屏状态：" + (c.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH ? "无触摸屏" : "支持触摸屏"));
        stringBuilder.append('\n');
        stringBuilder.append("移动信号国家码：" + c.mcc);
        stringBuilder.append('\n');
        stringBuilder.append("移动信号网络码：" + c.mnc);
        stringBuilder.append('\n');
        stringBuilder.append("Locales：" + c.getLocales());

        alert("Configuration", stringBuilder.toString());


    }

    @Override
    public void onConfigurationChanged(@NonNull Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        alert("通知", "系统设置有更新");
    }

    void syso(String message) {

        Log.d(getClass().getName(), message);

    }



    void tw(String text) {
        Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
    }

    void alert(String title, String message) {
        new AlertDialog.Builder(this)
                .setTitle(title)
                .setMessage(message)
                .create().show();
    }
}